<template>
    <rx-dialog @handOk="handOk" @cancel="cancel">
        <rx-layout style="width: calc(100% - 2px)">
            <div slot="left" width="200" showButton="true">
                <rx-category-tree ref="categoryTree" cat-key="FORM" :isGrant="true" :async="true" :appId="newAppId" @select="handSelect">
                </rx-category-tree>
            </div>
            <div slot="header">
                <div class="table-page-search-wrapper" border="false">
                    <a-form layout="inline">
                        <a-row :gutter="24">
                            <a-col :span="8">
                                <a-form-item :label="$ti18('rxForm.name','名称')">
                                    <a-input :placeholder="$ti18('rxForm.name','名称','','input')" v-model="queryParam.Q_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="8">
                                <a-form-item :label="$ti18('rxForm.rxAlias','别名')">
                                    <a-input :placeholder="$ti18('rxForm.rxAlias','别名','','input')" v-model="queryParam.Q_ALIAS__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="8">
                                  <span class="table-page-search-submitButtons">
                                    <a-button type="primary" @click="$refs.table.loadData()" icon="search">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                                    <a-button style="margin-left: 4px" @click="resetSearch2">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                                  </span>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
            </div>

            <div slot="center" style="margin: 10px">
                <rx-grid
                    ref="table"
                    :bordered="false"
                    :allowRowSelect="true"
                    :multiSelect="multiSelect"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formSolution/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    type="radio"
                    @selectChange="onSelectChange"
                    selectedRowKeys="selectedRowKeys"
                >
                    <span slot="isShare" slot-scope="{ text, record }">
                        {{record.createBy != "SHARE" ? $ti18('rxList.no', '否') : $ti18('rxList.yes', '是')}}
                    </span>
                  <span slot="shareAppName" slot-scope="{text,record}">
                          {{record.createBy == "SHARE"?$i18(record.updateBy,'应用名称'):curApp.appName}}
                        </span>
                </rx-grid>
            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>

import FormSolutionApi from '@/api/form/core/formSolution'
import {BaseList, RxLayout, Util,JsConstant} from "@lowcode/jpaas-common-lib"

export default {
    name: 'FormSolutionDialog',
    mixins: [BaseList],
    components: {
        RxLayout
    },
    props: {
        layerid: {
            type: String,
            default: ""
        },
        destroy: {
            type: Function
        },
        multiSelect: {
            type: Boolean,
            default: true
        },
        /**
         * 业务模型ID
         */
        boDefId:{
            type: String,
            default: ""
        },
        appId:{
            type: String,
            default: "0"
        }
    },
    data() {
        return {
            columns: [
                {
                    title: '#',
                    scopedSlots: {customRender: 'serial'},
                    dataIndex: 'serial',
                    type: 'indexColumn',
                    width: 60
                },
                {title: this.i18n('mapPane.schemeName','方案名称'), dataIndex: 'name', width: 120},
                {title: this.$ti18('rxForm.rxAlias','别名'), dataIndex: 'alias', width: 120},
                {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', width: 120},
                {
                    title: this.$ti18('rxList.share','共享'),
                    dataIndex: 'isShare',
                    width:80,
                    scopedSlots: { customRender: 'isShare' }
                },
              {
                title: this.$ti18('rxList.shareAppName', '所属应用'),
                dataIndex: 'shareAppName',
                width: 80,
                scopedSlots: { customRender: 'shareAppName' }
              }

            ],
            newAppId:this.appId,
        }

    },
    created() {
        this.queryParam.Q_IS_GENERATE_TABLE__I_EQ = 1;
        if(this.boDefId){
            this.queryParam["Q_BODEF_ID__S_EQ"] = this.boDefId;
        }
        this.needFilterAppId();
        let appId=this.curApp.appId;
        var queryAppId=this.appId;
        if(queryAppId && queryAppId!=0){
            this.newAppId =queryAppId;
            this.queryParam.Q_APP_ID__S_EQ=queryAppId;
            this.queryParam.SHARE = true;

        }else if (appId){
            this.newAppId = appId;
            //用来判断是否显示共享数据
            this.queryParam.SHARE = true;
        }
    },
    mounted() {
        if(!this.newAppId){
            //删除共享数据列
            this.$refs.table.initColumns(this.columns.splice(4,1));
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"formSolution",key);
        },
        getListByParams(parameter) {
            return FormSolutionApi.query(parameter)
        },
        getSoutions() {
            var row = this.selectedRows[0];
            return row;
        },
        cancel() {
            Util.closeWindow(this, "cancel");
        },
        resetSearch2() {
            this.$nextTick(() => {
                this.queryParam = {};
                this.queryParam.Q_IS_GENERATE_TABLE__I_EQ = 1;
                let appId = this.curApp.appId;
                if (appId) {
                    this.queryParam.Q_APP_ID__S_EQ = appId;
                    //用来判断是否显示共享数据
                    this.queryParam.SHARE = true;
                }
                this.$nextTick(() => {
                    this.$refs[this.table].loadData();
                })
            })
        },
        handOk(vm) {
            var rows = this.selectedRows;
            if (rows.length == 0) {
                vm.loading = false;
                this.$message.warning(this.$ti18('rxMsa.masWarn.selectOneRecord','请选择一行记录!'));
                return;
            }
            Util.closeWindow(this, "ok");
        },
        handSelect(selKeys,e) {
            if(selKeys.length==0){
                delete this.queryParam.Q_CATEGORY_ID__S_EQ;
            }else{
                var treeId=selKeys[0];
                if(treeId=='0') return;
                this.queryParam.Q_CATEGORY_ID__S_EQ=treeId;
            }
            this.loadData()
        }
    }
}
</script>
<style scoped>

</style>

